import request from '@/utils/request'

const FILE_BASE_URL = 'file'

export const uploadFile = (param, file) => {
  const params = new FormData()
  params.append('file', file)
  for (const i in param) {
    if (Object.prototype.hasOwnProperty.call(param, i)) {
      params.append(i, param[i])
    }
  }
  return request({
    url: FILE_BASE_URL,
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: params
  })
}

export const removeFile = (id) => {
  return request({
    url: FILE_BASE_URL,
    method: 'delete',
    params: { key: id }
  })
}

// 图片管理
export const getPicture = () => request({
  url: FILE_BASE_URL,
  method: 'get',
  headers: {
    'Authorization': getToken()
  }
})

export const uploadPicture = (params) => request({
  url: FILE_BASE_URL,
  method: 'post',
  data: params
})

export const deletePicture = (id) => request({
  url: FILE_BASE_URL,
  method: 'delete',
  params: {
    key: id
  }
})
